﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_nhapxuatInfo
    {
        private int _manx;
        private string _tennhapxuat;
        private int _nhan;

        public cs_erp_nhapxuatInfo()
        {
            this._manx = 0;
            this._tennhapxuat = " ";
            this._nhan = 0;

        }
        public int manx
        {
            get
            {
                return this._manx;
            }
            set
            {
                this._manx = value;
            }
        }
        public string tennhapxuat
        {
            get
            {
                return this._tennhapxuat;
            }
            set
            {
                this._tennhapxuat = value;
            }
        }
        public int nhan
        {
            get
            {
                return this._nhan;
            }
            set
            {
                this._nhan = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@manx";
            paraName[1] = "@tennhapxuat";
            paraName[2] = "@nhan";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._manx;
            paraValue[1] = this._tennhapxuat;
            paraValue[2] = this._nhan;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_NHAPXUAT", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tennhapxuat", "manx");
            cb.KetDuLieu(cbo, "ERP_NHAPXUAT", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[3];
            header[0] = "manx";
            header[1] = "tennhapxuat";
            header[2] = "nhan";

            string[] mappingname = new string[3];
            mappingname[0] = "manx";
            mappingname[1] = "tennhapxuat";
            mappingname[2] = "nhan";

            int[] colwidth = new int[3];
            colwidth[0] = 12;
            colwidth[1] = 300;
            colwidth[2] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("ERP_NHAPXUAT", datagrid, csdl.OpenTable("ERP_NHAPXUAT", condition), header, mappingname, colwidth, 3);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_NHAPXUAT", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._manx = Convert.ToInt32(ds.Tables[0].Rows[0]["manx"].ToString().Trim());
                this._tennhapxuat = ds.Tables[0].Rows[0]["tennhapxuat"].ToString().Trim();
                this._nhan = Convert.ToInt32(ds.Tables[0].Rows[0]["nhan"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }
        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select manx, tennhapxuat, nhan "
                + " from ERP_NHAPXUAT";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}